﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script language="javascript" type="text/javascript">
        //显示角色详细信息
        function showDetail(flag, a) {
            var detailDiv = a.parentNode.getElementsByTagName("div")[0];
            if (flag) {
                detailDiv.style.display = "block";
            }
            else
                detailDiv.style.display = "none";
        }
        //删除
        function deleteAccount() {
            var r = window.confirm("确定要删除此业务账号吗？删除后将不能恢复。");
            document.getElementById("operate_result_info").style.display = "block";
        }
        //开通或暂停

    </script>

</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="/index" class="index_on"></a></li>
        <li id="lia1"><a href="/role_list" class="role_off"></a></li>
        <li id="lia2"><a href="/admin_list" class="admin_off"></a></li>
        <li id="lia3"><a href="/fee_list" class="fee_off"></a></li>
        <li id="lia4"><a href="/account_list" class="account_off"></a></li>
        <li id="lia5"><a href="/service_list" class="service_off"></a></li>
        <li id="lia6"><a href="/bill_list" class="bill_off"></a></li>
        <li id="lia7"><a href="/report_list" class="report_off"></a></li>
        <li><a href="/userInfo" class="information_off"></a></li>
        <li><a href="/userModifyPwd" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--查询-->
        <div class="search_add">
            <div>OS 账号：<input type="text" id="os" value="" class="width100 text_search"/></div>
            <div>服务器 IP：<input type="text" id="ip" value="" class="width100 text_search"/></div>
            <div>身份证：<input type="text" id="card" value="" class="text_search"/></div>
            <div>状态：
                <select class="select_search" id="type">
                    <option>全部</option>
                    <option value="1">启用</option>
                    <option value="0">暂停</option>
                    <option value="2">删除</option>
                </select>
            </div>
            <div><input type="button" id="search" value="搜索" class="btn_search"/></div>
            <input type="button" value="增加" class="btn_add" onclick="location.href='service_add.html';"/>
        </div>
        <!--删除的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            删除成功！
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th class="width50">业务ID</th>
                    <th class="width70">账务账号ID</th>
                    <th class="width150">身份证</th>
                    <th class="width70">姓名</th>
                    <th>OS 账号</th>
                    <th class="width50">状态</th>
                    <th class="width100">服务器 IP</th>
                    <th class="width100">资费</th>
                    <th class="width200"></th>
                </tr>

            </table>
            <p>业务说明：<br/>
                1、创建即开通，记载创建时间；<br/>
                2、暂停后，记载暂停时间；<br/>
                3、重新开通后，删除暂停时间；<br/>
                4、删除后，记载删除时间，标示为删除，不能再开通、修改、删除；<br/>
                5、业务账号不设计修改密码功能，由用户自服务功能实现；<br/>
                6、暂停和删除状态的账务账号下属的业务账号不能被开通。</p>
        </div>
        <!--分页-->
        <div id="pages">

        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司 </p>
</div>
</body>
<script src="/js/jquery-3.2.1.js"></script>
<script>
    $("#search").click(function () {
        alert("点击事件执行");
        var osName = null;
        if ($("#os").val() != "") {
            osName = "%" + $("#os").val() + "%";
        }
        var ip = null;
        if ($("#ip").val() != "") {
            ip = $("#ip").val();
        }
        var status = null;
        if ($("#type option:selected").text() == "全部") {
            status = "%" + "%"
        } else {
            status = $("#type option:selected").val();
        }
        $.ajax({
            url: "/selectByOSName",
            type: "post",
            data: {
                osName: osName,
                ip: ip,
                card: $("#card").val(),
                status: status
            },
            success: function (result) {
                $("#datalist  tr:not(:first)").empty("");
                for (var i = 0; i < result.length; i++) {
                    var service = result[i];
                    var tr = $("<tr></tr>");
                    var serviceId = $("<td></td>");
                    var serId = $("<a href='/service_detail?serviceId=" + service.serviceId + "'></a>").text(service.serviceId);
                    serviceId.append(serId);
                    var accountId = $("<td></td>").text(service.accountId);
                    var idcardNo = $("<td></td>").text(service.account.idcardNo);
                    var realname = $("<td></td>").text(service.account.realName);
                    var osName = $("<td></td>").text(service.osUsername);
                    var statu = $("<td id='ttd'></td>").text(service.status == 1 ? '启用' : '暂停');
                    if (service.status == 2) {
                        statu = $("<td id='ttd'></td>").text("删除");
                    }
                    var unixHost = $("<td></td>").text(service.unixHost);
                    var costtype = $("<td></td>");
                    var a = $("<a class='summary' onmouseover='showDetail(true,this);' onmouseout='showDetail(false,this);'></a>").text(service.cost.costType);
                    var div = $("<div class='detail_info'></div>").text(service.cost.descr);
                    if (service.status == 2) {
                        var td = $("<td id='inputtd'></td>").css("display", "none");
                    } else {
                        td = $("<td id='inputtd'></td>").css("display", "block");
                    }
                    var in1 = $("<input type='button' value='暂停' class='btn_pause' id='btn' onclick='setState(" + service.serviceId + "," + service.status + ")'/>").val(service.status == 1 ? '暂停' : '启用');
                    var in2 = $("<input type='button' value='修改' class='btn_modify'  onclick='tiao(" + service.serviceId + ")'/>");
                    var in3 = $("<input type='button' value='删除' class='btn_delete'  onclick='setDelState(" + service.serviceId + ")'/>");
                    $("#datalist").append(tr.append(serviceId).append(accountId).append(idcardNo).append(realname).append(osName).append(statu).append(unixHost).append(costtype.append(a).append(div)).append(td.append(in1).append(in2).append(in3)));
                }
            }
        });
    });

    show();
    servicepage();
    function show() {
        $.ajax({
            url: "/selectAllModules",
            type: "post",
            success: function (result) {

                if (result.indexOf("角色管理") == -1) {
                    document.getElementById("lia1").style.display = "none"
                }
                if (result.indexOf("管理员") == -1) {
                    document.getElementById("lia2").style.display = "none"
                }
                if (result.indexOf("资费管理") == -1) {
                    document.getElementById("lia3").style.display = "none"
                }
                if (result.indexOf("账务账号") == -1) {
                    document.getElementById("lia4").style.display = "none"
                }
                if (result.indexOf("业务账号") == -1) {
                    document.getElementById("lia5").style.display = "none"
                }
                if (result.indexOf("账单管理") == -1) {
                    document.getElementById("lia6").style.display = "none"
                }
                if (result.indexOf("报表") == -1) {
                    document.getElementById("lia7").style.display = "none"
                }


            }

        });
    }

    function tiao(id) {
        window.location.href = "/service_modi?id=" + id;
    }

    function setState(serviceId, status) {
        $.ajax({
            url: "/updateStatu",
            type: "post",
            data: {
                service: serviceId,
                status: status
            },
            success: function (result) {
                window.location.href = result.msg
            }
        });

    }
    function setDelState(serviceId) {
        $.ajax({
            url: "/updateStatu",
            type: "post",
            data: {
                service: serviceId,
                status: 2
            },
            success: function (result) {
                window.location.href = result.msg
            }
        });

    }

    function servicepage() {
        $.ajax({
            url: "/servicepage",
            method: "post",
            data: {
                pageNum: 1,
                pageSize: 3
            },
            success: function (result) {

                resultData(result);


            }
        });
    }
    function page(pagenum) {
        $.ajax({
            url: "/servicepage",
            type: "post",
            data: {
                pageNum: pagenum,
                pageSize: 3
            },
            success: function (result) {
                resultData(result);
            }
        });
    }

    function resultData(result) {
        $("#datalist").html("");
        $("#datalist").append("<tr>" +
                "<th class='width50'>业务ID</th>" +
                "<th class='width70'>账务账号ID</th>" +
                "<th class='width150'>身份证</th>" +
                "<th class='width70'>姓名</th>" +
                "<th >账号</th>" +
                "<th class='width50'>状态</th>" +
                "<th class='width100'>服务器 IP</th>" +
                "<th class='width100'>资费</th>" +
                "<th class='width200'></th>" +
                "</tr>");
        var pagenum = result.pageNum;
        //每页显示几条数据
        var pagesize = result.pageSize;
        var size = result.size;
        var startrow = result.startRow;
        var endrow = result.startRow;
        var total = result.total;
        var pages = result.pages;
        var firstpage = result.firstPage;
        var prepage = result.prePage;
        var nextpage = result.nextPage;
        var lastpage = result.lastPage;
        var isfirstpage = result.isFirstPage;
        var islastpage = result.isLastPage;
        var haspreviouspage = result.hasPreviiousPage;
        var hasnextpage = result.hasNextPage;
        var navigatepages = result.navigatePages;
        var navigatepagenums = result.navigatepageNums;
        var serviceList = result.list;

        if (isfirstpage) {
            prepage = firstpage
        }
        if (islastpage) {
            nextpage = lastpage;
        }
        for (var i = 0; i < serviceList.length; i++) {
            var service = serviceList[i];
//            console.log(service);
            var tr = $("<tr></tr>");
            var serviceId = $("<td></td>");
            var serId = $("<a href='/service_detail?serviceId=" + service.serviceId + "'></a>").text(service.serviceId);
            serviceId.append(serId);
            var accountId = $("<td></td>").text(service.accountId);
            var idcardNo = $("<td></td>").text(service.account.idcardNo);
            var realname = $("<td></td>").text(service.account.realName);
            var osName = $("<td></td>").text(service.osUsername);
            var statu = $("<td id='ttd'></td>").text(service.status == 1 ? '启用' : '暂停');
            if (service.status == 2) {
                statu = $("<td id='ttd'></td>").text("删除");
            }
            var unixHost = $("<td></td>").text(service.unixHost);
            var costtype = $("<td></td>");
            var a = $("<a class='summary' onmouseover='showDetail(true,this);' onmouseout='showDetail(false,this);'></a>").text(service.cost.costType);
            var div = $("<div class='detail_info'></div>").text(service.cost.descr);
            if (service.status == 2) {
                var td = $("<td id='inputtd'></td>").css("display", "none");
            } else {
                td = $("<td id='inputtd'></td>").css("display", "block");
            }
            var in1 = $("<input type='button' value='暂停' class='btn_pause' id='btn' onclick='setState(" + service.serviceId + "," + service.status + ")'/>").val(service.status == 1 ? '暂停' : '启用');
            var in2 = $("<input type='button' value='修改' class='btn_modify'  onclick='tiao(" + service.serviceId + ")'/>");
            var in3 = $("<input type='button' value='删除' class='btn_delete'  onclick='setDelState(" + service.serviceId + ")'/>");
            $("#datalist").append(tr.append(serviceId).append(accountId).append(idcardNo).append(realname).append(osName).append(statu).append(unixHost).append(costtype.append(a).append(div)).append(td.append(in1).append(in2).append(in3)));
        }
        $("#pages").html("");
        var a11 = $("<a href='javascript:void(0)' onclick='page(" + firstpage + ")'></a>").text("首页");
        var a12 = $("<a href='javascript:void(0)' onclick='page(" + prepage + ")'></a>").text("上一页");
        $("#pages").append(a11).append(a12);
        for (var k = 1; k <= lastpage; k++) {
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + k + ")' >" + k + "</a>"));
        }
        var a13 = $("<a href='javascript:void(0)' onclick='page(" + nextpage + ")'></a>").text("下一页");
        var a14 = $("<a href='javascript:void(0)' onclick='page(" + lastpage + ")'></a>").text("尾页");
        $("#pages").append(a13).append(a14);
    }


</script>
</html>
